#include <stdio.h>

#include "arrlink.h"


#define NUM 3

int main(int argc,char **argv)
{


	 int i;
	 init();

	 Link firstNode=links[0];
	
 	 Link nowNode;


	 nowNode=firstNode;

	do
	{
		printf("%d\n",nowNode.item);
		nowNode=links[nowNode.pNext];

	}
	while(nowNode.item!=firstNode.item);	


	nowNode=firstNode;
	while(nowNode.pNext!=nowNode.pPre)
	{
	
		for(i=0;i<NUM;i++)
		{
			nowNode=links[nowNode.pNext];
		
		}


		printf("print the out number is:%d\n",nowNode.item);
		deleteNode(nowNode.item-1);
		

	
	}
	



	return 0;
}



void init()
{

	int i;
	for(i=0;i<SIZE;i++)
	{
		links[i].item=i+1;
		if(i==SIZE-1)
		{
			links[i].pNext=0;
		}
		else
		{
			links[i].pNext=i+1;;	
		}

	

		if(i==0)
		{
			links[i].pPre=SIZE-1;
		}
		else
		{
			links[i].pPre=i-1;;
		}




	}

}

Link deleteNode(Integer index)
{


	Link *pnowLink=NULL;
	if(index<0)
	{
		return links[0];
	}


	if(index>=SIZE)
	{
	
		return links[0];
	}


	pnowLink=&links[index];

	links[pnowLink->pPre].pNext=pnowLink->pNext;

	links[pnowLink->pNext].pPre=pnowLink->pPre;

	pnowLink->item=-1;


	pnowLink=&links[0];

	while(pnowLink->item==-1)
	{
	
		pnowLink=&links[pnowLink->pNext];
	}

	return *pnowLink;

}





